#define _CRT_SECURE_NO_WARNINGS 1
#include"List.h"
void SeqListInit(SeqList* ps) 
{
	assert(ps);
	ps->a =(SeqList*) malloc(4 * sizeof(int));
	ps->size = 0;
	ps->capacity = 4;
}
void SeqListDestroy(SeqList* ps)
{
	free(ps->a);
	ps->size = 0;
	ps->capacity = 0;
	ps->a = NULL;
}
void SeqListPrint(SeqList* ps)
{
	assert(ps);
	for (int i = 0; i < ps->size; i++)
		printf("%d ", ps->a[i]);
}
void Check(SeqList* ps)
{
	assert(ps);
	SeqList* p = NULL;
	ps->capacity *= 2;
	if (ps->size == ps->capacity)
	{
		p = (SeqList*)realloc(ps->a, ps->capacity * sizeof(int));
		ps->a = p;
	}
}
void SeqListPushBack(SeqList* ps,SLDateType x)
{
	assert(ps);
	Check(ps);
	ps->a[ps->size] = x;
	ps->size++;
}
void SeqListPushFront(SeqList* ps, SLDateType x)
{
	assert(ps);
	Check(ps);
	for (int i = ps->size - 1; i > 0; i--)
	{
		ps->a[i] = ps->a[i - 1];
	}
	ps->a[0] = x;
	ps->size++;
}
void SeqListPopFront(SeqList* ps)
{
	assert(ps);
	if (ps->size > 0)
		for (int i = 0; i < ps->size - 1; i++)
			ps[i] = ps[i + 1];
	ps->size--;
}
void SeqListPopBack(SeqList* ps)
{
	assert(ps);
	ps->size--;
}
int SeqListFind(SeqList* ps, SLDateType x)
{
	assert(ps);
	for (int i = 0; i < ps->size; i++)
		if (ps->a[i] == x)
			return i;
}
void SeqListErase(SeqList* ps, int pos)
{
	assert(ps);
	if (pos >= ps->size)
		return;
	for (int i = pos; i < ps->size - 1; i++)
		ps->a[i] = ps->a[i + 1];
	ps->size--;
}
void SeqListInsert(SeqList* ps, int pos, SLDateType x)
{
	assert(ps);
	if (pos > ps->size)
		return;
	for (int i = ps->size; i >= pos; i--)
		ps->a[i] = ps->a[i - 1];
	ps->a[pos] = x;
	ps->size++;
}
